package com.service;

import com.service.ITimeTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * 定时服务类
 */
@Service
public class TimeTaskServiceImpl implements ITimeTaskService {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 每 5秒去删除过期的zset中的value
     */
    @Override
    @Scheduled(cron = "0/5 * * * * ?")
    //秒，分，时，日期,星期，每隔多久定时清理数据，o/5 就是每隔5秒
    public void removeExpireMailCode(){
        redisTemplate.boundZSetOps("mail").removeRangeByScore(0,System.currentTimeMillis()-30*60*1000);

    }


}
